#ifndef AUDIOENCODER_H
#define AUDIOENCODER_H

extern "C" {
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
}

#include <vector>

class AudioEncoder
{
public:
    AudioEncoder();
    ~AudioEncoder();

    int InitAAC(int channels, int sample_rate, int bit_rate);
    void DeInit();

    AVPacket *Encode(AVFrame *frame, int stream_index, int64_t pts, int64_t time_base);
    int Encode(AVFrame *frame, int stream_index, int64_t pts, int64_t time_base, std::vector<AVPacket *> &packets);

    int GetFrameSize();//获取一帧数据，每个通道需要多少个采样点
    int GetSampleFormat(); //编码器需要的采样格式
    AVCodecContext *GetCodecContext();
    int GetChannels();
    int GetSampleRate();

private:
    char *printErrStr(int errNo);

private:
    int channels_ = 2;
    int sample_rate_ = 44100;
    int bit_rate_ = 128 * 1024;
    int64_t pts = 0;
    AVCodecContext *codec_ctx_ = NULL;
};

#endif // AUDIOENCODER_H
